package com.zxl.live.screen.screen.constant;

import android.content.Intent;

import com.zxl.live.tools.common.ApplicationHelper;

import java.lang.reflect.Field;

/**
 * 应用锁设置
 * Created by makai on 15-6-10.
 */
public class ScreenSetting {

    @SettingsDataSave.Settings(name = ISharedPreferences.SETTINGS_SCREEN_SIZE)
    public static int sEffciencySize = 1;

    @SettingsDataSave.Settings(name = ISharedPreferences.SETTINGS_SCREEN_TYPE)
    public static int sEffciencyType = 0;

    @SettingsDataSave.Settings(name = ISharedPreferences.SETTINGS_SCREEN_SWITCH)
    public static boolean sIsSwitchOpened = true;

    @SettingsDataSave.Settings(name = ISharedPreferences.SETTINGS_SCREEN_NOTIFICATION)
    public static boolean sIsNotificationEnabled = true;

    @SettingsDataSave.Settings(name = ISharedPreferences.SETTINGS_CALL_FLASH_SWITCH)
    public static boolean sCallFlashSwitch;

    @SettingsDataSave.Settings(name = ISharedPreferences.SETTINGS_CALL_FLASH_INFO)
    public static String sCallFlashInfo;

    @SettingsDataSave.Settings(name = ISharedPreferences.SETTINGS_SCREEN_LOCK_SWITCH)
    public static boolean sScreenLockSwitch = false;

    @SettingsDataSave.Settings(name = ISharedPreferences.SETTINGS_SCREEN_LOCK_WALLPAPER)
    public static String sScreenLockWallpaper;

//    fireflies-release.apk";   fireworks-release.apk

    @SettingsDataSave.Settings(name = ISharedPreferences.SETTINGS_SCREEN_LOCK_WALLPAPER_PLUGIN)
    public static String sScreenLockWallpaperPlugin;

    /**
     * 初始化设置数据
     */
    public static void init() {
        SettingsDataSave.initData(ScreenSetting.class, ISharedPreferences.SP_DEFAULT_MULTI_PROCESS);
    }

    /**
     * 保存应用锁数据
     * @param key
     * @param value
     */
    public static void saveLockerSettings(String key, Object value) {
        SettingsDataSave.saveData(ScreenSetting.class, ISharedPreferences.SP_DEFAULT_MULTI_PROCESS, key, value);
        notifyService(key);
    }

    private static void notifyService(String key) {
        Field[] fields = ScreenSetting.class.getFields();
        for (Field field : fields) {
            SettingsDataSave.Settings annotation = field.getAnnotation(SettingsDataSave.Settings.class);
            if (null != annotation && annotation.name().equals(key)) {
                Intent intent = new Intent(ApplicationHelper.getContext(), annotation.cls());
                intent.setAction(ICustomAction.ACTION_REFRESH_SETTINGS);
                intent.putExtra("data", key);
                ApplicationHelper.getContext().startService(intent);
            }
        }
    }

}
